package cn.yqn.org.service.impl;

import cn.yqn.basic.service.impl.BaseServiceImpl;
import cn.yqn.org.domain.Employee;
import cn.yqn.org.mapper.EmployeeMapper;
import cn.yqn.org.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class EmployeeServiceImpl extends BaseServiceImpl<Employee> implements IEmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    // 重写关联角色后的新增&修改和删除方法

    @Override
    public void update(Employee employee) {
        super.update(employee);
        // 根据Id删除角色
        employeeMapper.removeEmployeeRole(employee.getId());
        // 重新保存到表中
        employeeMapper.saveEmployeeRole(employee.getId(), employee.getRole_id());
    }

    @Override
    public void save(Employee employee) {
        employeeMapper.saveEmployeeRole(employee);
        employeeMapper.saveEmployeeRole(employee.getId(),employee.getRole_id());
    }

    @Override
    public void remove(long eid) {
        // 先删除t_employee_role
        employeeMapper.removeEmployeeRole(eid);
        employeeMapper.remove(eid);
    }

    @Override
    public List<Employee> findByShopId(Long shopId) {
        return employeeMapper.findByShopId(shopId);
    }
}
